package com.commonly.commonlyUsed.正则;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author guanym
 * @date 2021/11/24
 */
public class demo {

    public static void main(String[] args) {
        String str = "/?code=B0EF3682492DD669B07EBDD5323F5CAB&state=&responseStatus=100180\n";
        //万能公式 (.*?)
        //截取 code= 到 & 之间的字符
        Pattern pattern = Pattern.compile("code=(.*?)&");
        Matcher m = pattern.matcher(str);
        while(m.find()) {
            //正则之后会返回两个，code=B0EF3682492DD669B07EBDD5323F5CAB 和 B0EF3682492DD669B07EBDD5323F5CAB 我们直接拿第2个
            String string=m.group(1);
            System.out.println(string);
        }
    }
}
